"""
__init__.py

The directory where __init__.py file makes all files in 
the directory to belong to a module. 

Everything assigned here will be automatically available in the package
namespace (i.e CA3.morphology) . 
"""


def get_distances(mycell, save=False):
    """ 
    mycell      -- cell object
    fname       -- path and filename of the file to save 

    Returns an array with the id, segment and distance from the soma
    every segment in the cell object
    """
    from neuron import h 
    import numpy as np
    
    array = np.empty((0,3))
    mydist = list()
    if save is True:
        fp = open('distances.txt','w')

    h.distance(0, 0.5, sec=mycell.soma)
    
    for sec in mycell.allsec:
        mystring = sec.name()
        sec_id = mystring.split('.')[-1] 
        for seg in sec:
            dist = h.distance(seg.x,  sec=seg.sec)
            mydist.append(float(dist)) 
            array = np.append(array, [[sec_id, float(seg.x), dist]], axis=0)
            if save is True:
                fp.write("%4s\t%2.4f\t%2.4f\n"%(sec_id, float(seg.x), dist))

    if save is True:
        fp.close()

    return array
            
def ca3_15():
    """
    creates  cell object with CA3_15 morphology
    """
    from CA3_15 import CA3Cell
    return CA3Cell()

# list of the module packages that should be imported when import * 
# every module (or file) is a cell type
#__all__ = ['CA3_15']

